package com.interview.rpc.protocol;

import java.io.Serializable;

/**
 * RPC响应对象
 * 
 * 这个类用于封装服务端对RPC调用的响应结果，包含调用是否成功以及返回的数据
 * 实现Serializable接口是为了能够通过网络传输该对象
 */
public class Response implements Serializable {
    private static final long serialVersionUID = 1L;
    
    // 对应的请求ID，用于匹配请求和响应
    private String requestId;
    // 响应状态码，200表示成功，其他表示失败
    private int code;
    // 响应消息，通常在失败时包含错误信息
    private String message;
    // 响应数据，即方法调用的返回值
    private Object data;
    
    public Response() {}
    
    public Response(String requestId, int code, String message, Object data) {
        this.requestId = requestId;
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    // Getters and Setters
    public String getRequestId() {
        return requestId;
    }
    
    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
    
    public int getCode() {
        return code;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public Object getData() {
        return data;
    }
    
    public void setData(Object data) {
        this.data = data;
    }
    
    @Override
    public String toString() {
        return "Response{" +
                "requestId='" + requestId + '\'' +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}